<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<?php include 'conf/conf.inc.php'; 
	  include 'connect/connect.php';
	  include 'acaoCliente.php';
	  include 'utilSys.php';
	  
	$procurar = '';
	if (isset($_POST["procurar"]))
		  $procurar = $_POST["procurar"];
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta http-equiv="pragma" content="nocache">
<script language="javascript" type="text/javascript">
	function excluirRegistro(url) {
		if (confirm("Confirmar Exclusao?"))
			location.href = url ;
	}
</script>
<link rel=stylesheet href='css/cadastro.css' type='text/css' />
<link rel=stylesheet href='css/estilo.css' type='text/css' />
<script src="js/util.js" type="text/javascript"></script>
<title> <?php echo $title; ?> </title>
</head>
<body>
<?php include 'menu.php'; ?>
<form id="ListaClientes" name="ListaClientes" method="post" action="" >
    <fieldset>
            <legend>Procurar Vendas</legend>
    <input type="text" name="procurar" id="procurar" size="37">
    <button name="acao" id="acao" value="busca"  type="submit">
                <img src="images/form/magnifier.png" alt="Enviar"> Procurar
            </button>
    <button name="enviar" value="enviar" type="submit">
                <img src="images/form/add.png" alt="Enviar"> Adicionar
            </button>
      <br><br>
    <table width="100%"   border="1" align="left" id='painel'>
	
	<tr>
        <td width="90" align="center"><b>C&oacute;digo</b></td>
        <td width="400" ><b>Cliente</b></td>
        <td width="400" ><b>Vendedor</b></td>
        <td width="250" ><b>Data da Venda</b></td>
        <td width="250" ><b>Data de Vencimento</b></td>
        <td width="250" ><b>Data de Pagamento</b></td>
        <td width="250" ><b>Valor Total</b></td>
        <td width="20" ></td>
        <td width="20" ></td>
	</tr>
    <?php 
    $sql = "select venda.idvenda, cliente.nome, vendedor.nome,". 
		   " data,dataVencimento, dataPagamento, sum(produto_has_venda.quantidadeProduto * produto_has_venda.valorUnitario) as totalVenda".
           " from cliente, vendedor, venda, produto_has_venda".
           " where cliente.nome like \"$procurar%\"".
           " and venda.cliente_idcliente = cliente.idcliente".
           " and venda.vendedor_idvendedor = vendedor.idvendedor".
           " and produto_has_venda.venda_idvenda = venda.idvenda".
           " group by venda.idvenda";
	$result = mysql_query($sql, $link);
    
   while ($row = mysql_fetch_array($result)){       
?>
	<tr id = "dados" onMouseOver="javascript:this.style.backgroundColor='#B0C4DE'" onMouseOut="javascript:this.style.backgroundColor=''">
        <td align="center"><?php echo $row['idvenda'];?></td>
        <td width="400"><?php echo $row[1];?></td>
        <td><?php echo $row[2];?></td>
        <td><?php echo dataTracoToPadrao($row['data']);?></td>
        <td><?php echo dataTracoToPadrao($row['dataVencimento']);?></td>
        <td><?php echo dataTracoToPadrao($row['dataPagamento']);?></td>
        <td><?php echo $row['totalVenda'];?></td>
        <td><a href="javascript:excluirRegistro('acaoCliente.php?acao=excluir&codigo=<?php echo $row['idcliente'];?>')"><img border="0" src="images/form/delete.png" alt="Excluir"></a></td>
        <td><a href="cad_vendas.php?acao=editar&codigo=<?php echo $row['idvenda'];?>"><img border="0" src="images/form/application_edit.png" alt="Editar"></a></td>        
	 </tr>
   <?php } ?>       
    </table>
  <p>&nbsp;</p>
    </fieldset>
</form>

</body>

</html>